﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Dashboard.Models
{
    public class TimeTagsManager : ITimeTagsManager
    {
        Random randomizer;
        Dictionary<int, string> warnings;
        Dictionary<int, string> criticals;

        private static TimeTagsManager timeTagsManager = new TimeTagsManager();
        internal static ITimeTagsManager Instance
        {
            get { return timeTagsManager; }
        }

        private TimeTagsManager()
        {
            randomizer = new Random();
            warnings = GetErrors.GetWarningErrors();
            criticals = GetErrors.GetCriticalErrors();
        }

        public TimeTag GetTimeTag()
        {
            int forRandom = randomizer.Next(1, 11);
            if (forRandom < 2)
            {
                return new TimeTag(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, GetRandomCriticalError(), TypeOfError.Critical);
            }
            else if (forRandom < 5)
            {
                return new TimeTag(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, GetRandomWarningError(), TypeOfError.Warning);
            }
            else
            {
                return new TimeTag(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, "No Error", TypeOfError.NoError);
            }
        }

        private string GetRandomWarningError()
        {
            return warnings[randomizer.Next(1, warnings.Count() + 1)];
        }

        private string GetRandomCriticalError()
        {
            return criticals[randomizer.Next(1, criticals.Count() + 1)];
        }
    }
}